const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

/** @type {import('webpack').Configuration} */
module.exports = {
    mode: 'development',
    entry: './src/main.jsx',
    output: {
        filename: '[name].js',
        path: path.join(__dirname, 'dist'),
        // 告诉webpack输出兼容systemjs兼容代码
        libraryTarget: 'system',
    },
    externals: ['react', 'react-dom'],
    resolve: {
        extensions: ['.js', '.json', '.jsx'],
      },
    devtool:'source-map',
    devServer: {
        port: 8080,
        static: {
            directory:  path.join(__dirname, 'dist'),
        },
        historyApiFallback: true
    },
    module: {
        rules: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        '@babel/preset-react'
                    ]
                }
            }
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html',
            // 告诉HtmlWebpackPlugin不需要把构建结果自动注入html中
            inject: false
        })
    ]
}